package CertificateAuthority;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.security.PrivateKey;


public class MyPrivateKey {
	private PrivateKey privateKey;
	
	public MyPrivateKey(PrivateKey privateKey) {
		this.privateKey = privateKey;
	}
	
	public boolean ToFile(String onderwerp) {
		 try{
			  // Create file 
			  FileWriter fstream = new FileWriter("private_"+ onderwerp + ".key");
			  BufferedWriter out = new BufferedWriter(fstream);
			  byte[] data = privateKey.getEncoded();
			  for(int i = 0; i < data.length; i++) {
				  out.write(data[i]);
			  }
			  //Close the output stream
			  out.close();
			  return true;
		  }catch (Exception e){//Catch exception if any
			  System.err.println("Error: " + e.getMessage());
		  }
		return false;
	}
	
}
